package model;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.ck.hzq.R;

import java.util.List;

import Bean.GetMainActivityDataBean;
import Utils.CheckPhoneNumberUtils;

public class ListviewMainActivityAdapter extends BaseAdapter {

    private List<GetMainActivityDataBean.DataBean.NewsBean> data;//数据

    private Context context;//上下文

    public ListviewMainActivityAdapter(List<GetMainActivityDataBean.DataBean.NewsBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.listviewenterpriseassistance_item1, null, false);
            viewHolder = new ViewHolder();
            viewHolder.linearlayout_linear = (LinearLayout) view.findViewById(R.id.listviewbook_linear);
            viewHolder.imageView = (ImageView) view.findViewById(R.id.listviewenterprise_img);
            viewHolder.textView1 = (TextView) view.findViewById(R.id.enterprise_txt1);
            viewHolder.textView2 = (TextView) view.findViewById(R.id.enterprise_txt2);
            viewHolder.textView3 = (TextView) view.findViewById(R.id.enterprise_txt3);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        Glide.with(context).load(data.get(position).getNewImag()).into(viewHolder.imageView);
        viewHolder.textView1.setText(data.get(position).getBt());
        viewHolder.textView2.setText(CheckPhoneNumberUtils.settime(data.get(position).getPushDate() + ""));
        viewHolder.textView3.setText(data.get(position).getReadNumber() + " 阅读");

        //TODO
        //改为 跳转webview浏览网页
//        viewHolder.linearlayout_linear.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(context, ProductActivity.class);
//                context.startActivity(intent);
//            }
//        });
        return view;
    }

    private class ViewHolder {
        LinearLayout linearlayout_linear;
        ImageView imageView;
        TextView textView1, textView2, textView3;
    }

}
